#include <fstream>
#include <vector>
using namespace std;

template <typename T>
void read(vector <T> &data) {
    int length;
    ifstream in("input.txt");
    in >> length;
    data.resize(length);
    for (int i = 0; i < length; ++i) {
        in >> data[i];
    }
    return;
}

template <typename T>
void max_to_end(vector <T> &data) {
    int position = 0;
    if (data.empty()) {
        return;
    }
    for (int i = 0; i < data.size(); ++i) {
        if (data[i] > data[position]) {
            position = i;
        }
    }
    swap(data[position], data.back());
    return;
}

template <typename T>
void print(vector <T> &data) {
    ofstream out("output.txt");
    for (int i = 0; i < data.size(); ++i) {
        out << data[i] << ' ';
    }
    return;
}

int main() {
    vector <int> data;
    read(data);
    max_to_end(data);
    print(data);
}